//
//  MessageCell.m
//  NiuBanGold
//
//  Created by Billy on 15/12/8.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "MessageCell.h"

@interface MessageCell ()

@property (nonatomic, strong) UIImageView *imageView_readStatus;//读与未读的标志
@property (nonatomic, strong) UILabel *label_title; //消息title
@property (nonatomic, strong) UILabel *label_time; //消息时间
@property (nonatomic, strong) UILabel *label_messageContent;//消息内容

@end

@implementation MessageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self setBackgroundColor:BASECOLOR];
        [self subViewsCreation];
    }
    
    return self;
}

#pragma mark - sub view createon

- (void) subViewsCreation {
    
    //cell 由三部分组成1 . 顶部20像素的view 2. 左边80像素的view  3. 右侧640像素的view
    
    //1.top view
    
    UIView *view_top = [UsefulUtil viewCreationWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, MULTIPLYHEIGHT(20.0/2)) backgroundColor:BASECOLOR backGroundImage:nil];
    
    [self.contentView addSubview:view_top];
    
    //2. 右边640像素view
    
    UIView *view_right = [UsefulUtil viewCreationWithFrame:CGRectMake(MULTIPLYWIDTH(80.0/2), CGRectGetMaxY(view_top.frame), SCREEN_WIDTH - MULTIPLYWIDTH(110.0/2), MULTIPLYHEIGHT(160.0/2)) backgroundColor:[UIColor whiteColor] backGroundImage:nil];
    
    [self.contentView addSubview:view_right];
    
    [view_right.layer setBorderWidth:1.0];
    [view_right.layer setBorderColor:APPCOLOR(@"#d3d3d3").CGColor];
    [view_right.layer setCornerRadius:8.0];
    [view_right setClipsToBounds:YES];

    
    //3. 左边80像素view
    
    UIView *view_left = [UsefulUtil viewCreationWithFrame:CGRectMake(0, CGRectGetMaxY(view_top.frame), MULTIPLYWIDTH(80.0/2), MULTIPLYHEIGHT(160.0/2)) backgroundColor:BASECOLOR backGroundImage:nil];
    
    [self.contentView addSubview:view_left];
    
    /**
        给每个view添加各自的子view
        view_left
     */
    
    self.imageView_readStatus = [[UIImageView alloc] initWithFrame:CGRectMake(MULTIPLYWIDTH(30.0/2), MULTIPLYHEIGHT(44.0/2), MULTIPLYWIDTH(18.0/2), MULTIPLYHEIGHT(18.0/2))];
    
    [view_left addSubview:self.imageView_readStatus];
    
    [self.imageView_readStatus.layer setCornerRadius:MULTIPLYWIDTH(9.0/2)];
    [self.imageView_readStatus setBackgroundColor:REDCOLOR];
    
    UIImageView *imageView_arraow = [UsefulUtil imageViewCreationWithFrame:CGRectMake(iPhone6p?MULTIPLYWIDTH(66.0/2):MULTIPLYWIDTH(69.0/2), self.imageView_readStatus.frame.origin.y, MULTIPLYWIDTH(16.0/2), MULTIPLYHEIGHT(24.0/2)) image:[UIImage imageNamed:@"messageArrow"]];
    
    [view_left addSubview:imageView_arraow];
    

    //view right
    
    self.label_title = [UsefulUtil labelCreationWithFrame:CGRectMake(MULTIPLYWIDTH(20.0/2), MULTIPLYHEIGHT(16.0/2),view_right.bounds.size.width/2, MULTIPLYHEIGHT(26.0/2)) textColor:APPCOLOR(@"#434343") fontName:[UIFont boldSystemFontOfSize:iPhone4?11.0:13.0] text:@""];
    
    self.label_time = [UsefulUtil labelCreationWithFrame:CGRectMake(CGRectGetMaxX(self.label_title.frame), MULTIPLYHEIGHT(16.0/2),view_right.bounds.size.width/2 -  MULTIPLYWIDTH(50.0/2), MULTIPLYHEIGHT(26.0/2)) textColor:APPCOLOR(@"#989898") fontName:[UIFont systemFontOfSize:iPhone4?11.0:12.0] text:@""];
    
    [self.label_time setAdjustsFontSizeToFitWidth:YES];
    [self.label_title setAdjustsFontSizeToFitWidth:YES];
    
    [view_right addSubview:self.label_title];
    [view_right addSubview:self.label_time];
    
    [self.label_time setTextAlignment:NSTextAlignmentRight];
    
    self.label_messageContent = [[UILabel alloc] initWithFrame:CGRectMake(MULTIPLYWIDTH(20.0/2), CGRectGetMaxY(self.label_title.frame) + MULTIPLYHEIGHT(32.0/2), view_right.bounds.size.width - MULTIPLYWIDTH(20.0/2), MULTIPLYHEIGHT(62.0/2))];
    
    [self.label_messageContent setNumberOfLines:0];
    
    [self.label_messageContent setTextColor:APPCOLOR(@"#434343")];
    [self.label_messageContent setFont:[UIFont systemFontOfSize:12.0]];

    [view_right addSubview:self.label_messageContent];
}


- (void)layoutSubviews {
    
    [self.label_title setText:self.message.message_title];
    [self.label_time setText:self.message.message_date];
    
    [self.label_messageContent setText:self.message.message_contnet];
    
    if ([self.message.message_status isEqualToString:@"0"]) { //未读
        
        [self.imageView_readStatus setBackgroundColor:REDCOLOR];
    }else {
        
        [self.imageView_readStatus setBackgroundColor:APPCOLOR(@"#d3d3d3")];
    }
}

@end
